//
//  WBViewController.swift
//  weibo
//
//  Created by yanghong on 15/12/5.
//  Copyright © 2015年 杨鸿. All rights reserved.
//

import UIKit
import SVProgressHUD
class WBViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = WBTabBar()
        
        tabBar.composeButtonClickClosure = { [weak self] in
            
            if !WBUserAccountViewModel.sharedAccount.userLogon {
                SVProgressHUD.showErrorWithStatus("请先登录")
                return
            }
            
            let composeView = WBComposeView()
            
            composeView.show(self)
            
         
        }
        
        tabBar.backgroundImage = UIImage(named: "tabbar_background")
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(WBHomeTableViewController(), title: "首页", imgName:"tabbar_home" )
        addChildViewController(WBMessageTableViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(WBDiscoverTableViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(WBProfileTableViewController(), title: "我", imgName: "tabbar_profile")

    }

}
extension WBViewController {


    func addChildViewController(childController: UIViewController ,title: String ,imgName:String) {
        
         tabBar.tintColor = UIColor.orangeColor()
        // 设置控制器 title
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        let textColorAttribute = [NSForegroundColorAttributeName :UIColor.orangeColor()]
        
        childController.tabBarItem.setTitleTextAttributes(textColorAttribute, forState: .Selected)
        
        //使用导航控制器包起来
        let nav = WBNavigationController(rootViewController: childController)
        addChildViewController(nav)
        
    }


}